package com.icangya.DAO.impl;


import com.icangya.DAO.IFbOrderDAO;
import com.icangya.domain.FbOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class FbOrderDAOImpl extends  BaseDAO<FbOrder> implements IFbOrderDAO {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public FbOrder getFbOrderByOrderId(String orderId) {
        String hql="from FbOrder fo where fo.orderId= ? ";
      List<FbOrder> list= (List<FbOrder>) getHibernateTemplate().find(hql,orderId);
          if(list.size()>0)
              return list.get(0);
          return null;
    }

    @Override
    public  List<FbOrder> getFbOrderAll() {
        String hql="from FbOrder fo order by fo.createTime desc";
        List<FbOrder> list= (List<FbOrder>) getHibernateTemplate().find(hql);
        if(list.size()>0)
            return list;
        return null;
    }

    @Override
    public List<FbOrder> getUserFbOrder(String openId) {
        String hql = "from FbOrder fo where fo.openId=?";
        List<FbOrder> list = (List<FbOrder>) getHibernateTemplate().find(hql, openId);
        if(list.size()>0)
            return list;
        return null;
    }

    @Override
    public List<FbOrder> getOrderByOutTrantId(String orderNum) {
        String hql="from FbOrder fo where fo.orderId = ? ";
        List<FbOrder> list= (List<FbOrder>) getHibernateTemplate().find(hql,orderNum);
        if(list.size()>0)
            return list;
        return null;
    }


    @Override
    public List<FbOrder> getFbOrderStatusAll(int status, int paymentStatus) {
        String hql="from FbOrder fo where fo.status=? and fo.paymentStatus=? order by fo.createTime desc";
        List<FbOrder> list= (List<FbOrder>) getHibernateTemplate().find(hql,status,paymentStatus);
        if(list.size()>0)
            return list;
        return null;
    }
}
